package typeConversion

import (
	"errors"
	"fmt"
	"strconv"
)

func ToInt(p_in interface{}) (int, error) {
	if p_in == nil {
		return 0, errors.New("too.typeConversion ToInt err: Parameters not supported, Parameters is nil")
	}
	switch p_in.(type) {
	case string:
		return strconv.Atoi(p_in.(string))
	case int:
		return p_in.(int), nil
	case int32:
		return int(p_in.(int32)), nil
	case int64:
		return int(p_in.(int64)), nil
	case float32:
		return int(p_in.(float32)), nil
	case float64:
		return int(p_in.(float64)), nil
	default:
		return 0, errors.New("too.typeConversion ToInt err: Parameters not supported,The parameter type is " + fmt.Sprintf("%T", p_in))
	}
}

func stringToInt(p_in string) (int, error) {
	return strconv.Atoi(p_in)
}

func Int32Toint(p_in int32) (int, error) {
	return int(p_in), nil
}

func int64Toint(p_in int64) (int, error) {
	return int(p_in), nil
}

func float32ToInt(p_in float32) (int, error) {
	return int(p_in), nil
}

func float64ToInt(p_in float64) (int, error) {
	return int(p_in), nil
}
